package com.epi.web.log.Impl;

import com.epi.one.basic.log.WinHandler;

import java.io.IOException;
import java.util.logging.*;

/**
 * @author dxy
 * @version 1.0
 */
public class JulLogger {

    private static final Logger log = Logger.getLogger("JulLogger");

    public static void main(String[] args) throws IOException {
        log.info("【原生 jul】 " + log.getClass().getName());
        for (int i = 0; i < 4; i++) {
            julLog(i);
        }
    }

    private static void julLog(Integer handleCase) throws IOException {
        Handler handler = switch (handleCase) {
            case 0 -> new ConsoleHandler();
            case 1 -> new FileHandler("src/main/resources/txt/log.txt", false);
            case 2 -> new SocketHandler("localhost", 8088);  //开端口监听
            case 3 -> new WinHandler(); // 输出到GUI JTextArea
            default -> throw new IllegalArgumentException("Unsupported case: " + handleCase);
        };

        handler.setLevel(Level.ALL);

        log.setUseParentHandlers(false); // 关闭默认的控制台 Handler
        log.addHandler(handler);         // 使用自定义的控制台 Handler
        log.setLevel(Level.ALL);

        log.severe("SEVERE: This is an error message");
        log.warning("WARNING: This is a warning message");
        log.info("INFO: This is an info message");
        log.config("CONFIG: This is a config message");
        log.fine("FINE: This is a fine message");
        log.finer("FINER: This is a finer message");
        log.finest("FINEST: This is a finest message");
    }
}
